package com.explorx.sns.puma.im.core.chat.command;

import com.alibaba.fastjson2.JSON;
import com.explorx.sns.puma.im.core.chat.PushService;
import com.explorx.sns.puma.im.core.chat.message.ChatMessage;
import com.explorx.sns.puma.im.core.chat.message.MessageCmd;
import com.explorx.sns.puma.im.core.controller.MessageGatewayService;
import com.google.common.base.Preconditions;
import lombok.Data;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Objects;

@Service
public class RecallMessageCommand implements MessageCommand{

    @Resource
    private MessageGatewayService messageGatewayService;

    @Resource
    private PushService pushService;

    @Override
    public void execute(ChatMessage cmdData) {
        final RemoveMessageData removeMessageData = (RemoveMessageData) parseCmd(cmdData.getMessage());
        messageGatewayService.revokeMessage(cmdData.getSenderId()
                ,cmdData.getCid()
                ,removeMessageData.getMsgId());

    }

    @Override
    public Object parseCmd(String cmdData) {
        return JSON.parseObject(cmdData,RemoveMessageData.class);
    }

    @Override
    public int cmd() {
        return MessageCmd.RECALL_MSG.getValue();
    }

    @Data
    static class RemoveMessageData implements Serializable {
        /**
         * 消息id
         */
        private Long msgId;
    }
}
